package com.diaohw.module.file.controller;

import com.diaohw.module.file.obj.dto.AccountFileDTO;
import com.diaohw.module.file.obj.dto.FileTagDTO;
import com.diaohw.module.file.obj.query.AccountFileQuery;
import com.diaohw.module.file.obj.vo.AccountFileVO;
import com.diaohw.module.file.service.AccountFileService;
import com.diaohw.platform.common.obj.page.PageResultVo;
import com.diaohw.platform.common.validator.InsertGroup;
import com.diaohw.platform.common.validator.UpdateGroup;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * <p>
 * 用户上传表 前端控制器
 * </p>
 *
 * @author D-Hw
 * @since 2024-11-05
 */
@Tag(name = "用户文件表")
@RestController
@RequestMapping("/account-file")
public class AccountFileController {

    @Resource
    private AccountFileService service;

    @PostMapping
    @Operation(summary = "新增")
    public AccountFileVO create(@Validated(InsertGroup.class) AccountFileDTO data,
                                @Parameter(name = "file") @RequestPart("file") MultipartFile file) {
        return service.create(data, file);
    }

    @PutMapping("/{id}")
    @Operation(summary = "更新")
    public AccountFileVO update(@PathVariable("id") String id, @RequestBody @Validated(UpdateGroup.class) AccountFileDTO data) {
        return service.update(id, data);
    }

    @DeleteMapping("/{id}")
    @Operation(summary = "删除")
    public Boolean delete(@PathVariable("id") String id) {
        return service.delete(id);
    }

    @DeleteMapping
    @Operation(summary = "删除")
    public Boolean delete(@RequestBody List<String> ids) {
        return service.delete(ids);
    }


    @GetMapping("/{id}")
    @Operation(summary = "依据ID查看信息")
    public AccountFileVO detail(@PathVariable("id") String id) {
        return service.detail(id);
    }

    @GetMapping
    @Operation(summary = "查询列表")
    public List<AccountFileVO> all(AccountFileQuery query) {
        return service.findByList(query);
    }

    @GetMapping("/page")
    @Operation(summary = "分页查看")
    public PageResultVo<AccountFileVO> page(AccountFileQuery query) {
        return service.findByPage(query);
    }

    @PostMapping("/tag")
    @Operation(summary = "标签分组")
    public Boolean tag(@RequestBody FileTagDTO data) {
        return service.tag(data);
    }
}
